package org.fle4y.example.aio.chat;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.logging.Logger;

import org.fle4y.common.utils.log.LogUtil;
import org.fle4y.framework.net.Message;
import org.fle4y.framework.net.Protocal;

/**
 * author : xiehui<br>
 * company : northking <br>
 * Create at: 2012-6-13<br>
 * @version : 1.0<br>
 * mailto:flexie@foxmail.com<br>
 *  Description :
 */
public class ChatProtocal implements Protocal{
	private static final Logger log = LogUtil.getLogger(ChatProtocal.class.getName());
	public Message transfer(ByteBuffer buffer) {
		ChatMessage msg=new ChatMessage();
		byte[] bs02=new byte[buffer.limit()];
		buffer.get(bs02);
		String content = new String(bs02,Charset.forName("UTF-8"));
		String[] strs =content.split("[:]");
		msg.setType(strs[0]);
		msg.setName(strs[1]);
		msg.setMessage(strs[2]);
		msg.setContent(ByteBuffer.wrap(bs02));
		log.info("协议转换消息"+msg.getMessage());
		return msg;
	}

}
